﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace SheepStorage.API.Filter
{
    public class GlobalFilter : IExceptionFilter
    {
        ILogger<GlobalFilter> logger;
        public GlobalFilter(ILogger<GlobalFilter> logger)
        {
            this.logger = logger;
        }

        public void OnException(ExceptionContext context)
        {
            // throw new NotImplementedException();
            // 写异常日志
            logger.LogError("【全局异常过滤器】：" + context.Exception.Message);
            context.ExceptionHandled = true;
        }
    }
}
